package com.yonyou.cloud.member.domainmodel.vo;

import com.yonyou.cloud.member.exceptions.IllegalKeyException;

import java.time.Instant;

public class EntityId {
    private Long id;
    private long ts;

    public EntityId(Long id) {
        if (id == null) {
            throw new IllegalKeyException();
        }
        this.id = id;
        this.ts = Instant.now().toEpochMilli();
    }

    public Long getId() {
        return id;
    }

    public long ts() {
        return ts;
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null || !(obj instanceof EntityId)) {
            return false;
        }
        return id.equals(((EntityId) obj).id);
    }

    @Override
    public String toString() {
        return id.toString();
    }
}